package com.example.quartz3.quartz;

import org.quartz.*;

import java.util.Date;

@DisallowConcurrentExecution
@PersistJobDataAfterExecution
public class MyJob implements Job {
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        System.out.println("Myjob execute:"+new Date());

        //获取jobData
//        JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
//        JobDataMap triggerDataMap = context.getTrigger().getJobDataMap();
//        JobDataMap mergedJobDataMap = context.getMergedJobDataMap();
//        String jobData = (String)jobDataMap.get("job");
//        System.out.println(jobData);

        JobDetail jobDetail = context.getJobDetail();
        JobDataMap jobDataMap = jobDetail.getJobDataMap();
        int count = jobDataMap.getInt("count");

        jobDataMap.put("count",count+1);
        System.out.println(count);

//        System.out.println(System.identityHashCode(context.getJobDetail()));;
//        System.out.println(System.identityHashCode(context.getJobInstance()));
//        System.out.println(System.identityHashCode(context.getTrigger()));
//        try {
//            Thread.sleep(3000);
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }
    }
}
